﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;


public partial class MeetingRoomManager_ModifyMeetiongRoom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlType.DataSource = new TableTypeManager().GetAllTableType();
            ddlType.DataBind();
            ListItem ee = new ListItem("请选择");
            ddlType.Items.Insert(0, ee);
            string no = Request.QueryString["no"];
            if (no != null)
            {
                MeetingRoom room = new MeetingRoomManager().GetAllMeetingRoom(no);
                lbNo.Text = room.RoomNo;
                txtName.Text = room.RoomName;
                this.ddlType.Text = room.RoomType.TypeName;
                txtArea.Text = room.RoomArea.ToString();
                txtCounts.Text = room.Counts.ToString();
                txtEquipment.Text = room.Equipment;
                Image1.ImageUrl = room.RoomImge;
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (CheckEmpty())
        {
            MeetingRoom room = new MeetingRoom();
            room.RoomNo = Request.QueryString["no"];
            room.RoomName = this.txtName.Text.Trim();
            TableType type = new TableType();
            type.TypeId = Convert.ToInt32(this.ddlType.SelectedItem.Value);
            type.TypeName = ddlType.SelectedItem.Text;
            room.RoomType = type;
            room.RoomArea = Convert.ToDouble(this.txtArea.Text);
            room.Counts = Convert.ToInt32(this.txtCounts.Text);
            room.Equipment = this.txtEquipment.Text;
            room.RoomImge = Server.MapPath("UploadPic") + fuRoomImge.FileName;
            new MeetingRoomManager().UpdateMeetingRoom(room);
        }
    }
    private bool CheckEmpty()
    {
        if (this.txtName.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('会议室名称不能为空！')</script>");
            return false;
        }
        if (this.txtArea.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('使用面积不能为空！')</script>");
            return false;
        }
        if (this.txtCounts.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('容纳人数不能为空！')</script>");
            return false;
        }
        if (this.txtEquipment.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('办公设备不能为空~')</script>");
            return false;
        }
        if (this.ddlType.Text == "请选择")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('您还没有选择类型！')</script>");
            return false;
        }
        if (this.fuRoomImge.FileName == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('您还没有上传会议室图片！')</script>");
            return false;
        }
        return true;
    }
}